﻿using MediatR;
using PublicClass;
using S.RBAC.Infrastructure.Interface;
using S.RBAC.Read.Api.Application.Command.StaffCommand;

namespace S.RBAC.Read.Api.Application.CommandHandlers.StaffHandler
{
    public class StaffGetAllCommandHandler : IRequestHandler<StaffGetAllCommand, List<SelectList>>
    {
        protected readonly IStaffRepository _staff;

        public StaffGetAllCommandHandler(IStaffRepository staff)
        {
            _staff = staff;
        }

        public async Task<List<SelectList>> Handle(StaffGetAllCommand request, CancellationToken cancellationToken)
        {
            List<SelectList> list = new List<SelectList>();

            var info = await _staff.GetAllStaff();

            foreach (var item in info)
            {
                list.Add(new SelectList
                {
                    Id = item.StaffId,
                    Name = item.StaffName
                });
            }

            return list;
        }
    }
}
